const express=require('express');
const path=require('path');
const app=express();
let arry=[{id:1,name:'首页',url:'/',},{id:2,name:'房源管理',url:'/fangyuan',child:[{childId:1,name:'房源管理child1',url:'/fangyuan1'},{childId:2,name:'房源管理child2',url:'/fangyuan2'}]},{id:3,name:'房东管理',url:'',child:[{childId:1,name:'房东管理child1',url:''},{childId:2,name:'房东管理child2',url:''}]},{id:4,name:'用户管理',url:''},{id:5,name:'合约管理',url:''},{id:6,name:'问答管理',url:'/faq'}];
let tableData=[{
    number: 1,
    title: '问题1',
    author: '作者1',
    reading:1000,
    reply:500,
    date:'2016-05-04'
  }, {
    number: 2,
    title: '问题2',
    author: '作者2',
    reading:1000,
    reply:500,
    date:'2016-05-05'
  }, {
    number: 3,
    title: '问题3',
    author: '作者3',
    reading:1000,
    reply:500,
    date:'2016-05-06'
  }, {
    number: 4,
    title: '问题4',
    author: '作者4',
    reading:1000,
    reply:500,
    date:'2016-05-07'
  }]

app.use(express.static(path.join(__dirname,'public'),{index:'index.html'}));
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With,Content-Type");
    //res.header("Content-Type", "application/json;charset=utf-8");  //注，如果包括页面等非json, 不要这句
    next();
});

app.get('/Backstage',(req,res)=>{
   
    res.send(arry);
});
app.get('/faq',(req,res)=>{
   
    res.send(tableData);
});
app.listen(8888,()=>{
    console.log('服务已启动');
});